package httpHandler

import (
	"gitee.com/zaiqiang231/lovesport-user-service/app/http/service"
	"gitee.com/zaiqiang231/lovesport-user-service/app/model/req"
	"github.com/gin-gonic/gin"
	"github.com/gin-gonic/gin/binding"
	"github.com/go-playground/validator/v10"
	"net/http"
)

type SysOperationRecordHandler struct {
}

func (*SysOperationRecordHandler) GetList(c *gin.Context) {
	var request req.SearchOperationRecordReq
	if err := c.ShouldBindBodyWith(&request, binding.JSON); err != nil {
		WriteResponse(c, http.StatusBadRequest, err.Error(), nil)
		return
	}

	validate := validator.New()
	if err := validate.Struct(request); err != nil {
		WriteResponse(c, http.StatusBadRequest, err.Error(), nil)
		return
	}

	list, total, err := service.ServiceOperationRecordInstance.GetList(request)
	if err != nil {
		WriteResponse(c, http.StatusInternalServerError, err.Error(), nil)
		return
	}
	WriteResponse(c, 0, "success", gin.H{
		"list":     list,
		"total":    total,
		"page":     request.Page,
		"pageSize": request.PageSize,
	})
}

func (*SysOperationRecordHandler) DeleteList(c *gin.Context) {
	var request req.IdsReq
	if err := c.ShouldBindBodyWith(&request, binding.JSON); err != nil {
		WriteResponse(c, http.StatusBadRequest, err.Error(), nil)
		return
	}

	validate := validator.New()
	if err := validate.Struct(request); err != nil {
		WriteResponse(c, http.StatusBadRequest, err.Error(), nil)
		return
	}

	err := service.ServiceOperationRecordInstance.DeleteList(request)
	if err != nil {
		WriteResponse(c, http.StatusInternalServerError, err.Error(), nil)
		return
	}
	WriteResponse(c, 0, "success", nil)
}
